﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using ShellUtils;



namespace WindowsFormsApplication1
{

    public partial class Form1 : Form
    {
        OpenFileDialog dlg = new OpenFileDialog();
        public ImageList imageList = new ImageList();
        public List<String> imageFileNameList = new List<String>();
        List<DateTime> imageModifiedList = new List<DateTime>();
        List<DateTime> imageCreatedList = new List<DateTime>();
        public List<string> imageLocation = new List<string>();
        List<Button> dragDropNodeButtons = new List<Button>();
        List<Button> parentNodeButtons = new List<Button>();
        List<Button> newButtons = new List<Button>();
        int browse = 0;

        public Color parentButtonColor = Color.LightBlue;
        public Color childButtonColor = Color.LemonChiffon;
        public Color formBackg = Color.Empty;

        String whichTagToDelete;
        String whichAlbumToDelete;

        //collection to keep track of how many items added to album or tag
        List<int> trackNumItems = new List<int>();
        List<int> trackNumItemsHistory = new List<int>();

        Hashtable allAlbums = new Hashtable();       // Hash map of String : album name and ArrayList : collection of album images location
        Hashtable allErasedAlbums = new Hashtable();       // Hash map of String : album name and ArrayList : collection of album images location
        Hashtable allImageTags = new Hashtable();    // Hash map of a image location and ArrayList of strings which are it's tags
        Hashtable allImageRatings = new Hashtable(); // Hash map of a image location and an int representing it's rating
        ArrayList actionHistory = new ArrayList();
        ArrayList undoHistory = new ArrayList();
        bool undoing = false;
        bool redoing = false;
        ArrayList listViewHistory = new ArrayList(); // array of they type of images to be displayed in list view
        ArrayList backHistory = new ArrayList();
        Hashtable buttonImages = new Hashtable();
        Hashtable allErasedTags = new Hashtable();

        bool backing = false;
        bool forwarding = false;
        System.Windows.Forms.Timer activityTimer = new System.Windows.Forms.Timer();
        bool firstrun = true;
        DictionaryEntry theView;
        public string defaultFrom = "";
        public List<string> fromAddress = new List<string>();
        public List<string> toAddess = new List<string>();

                    public string dcolor = "Black";
            public string dsound = "None";
            public string dtime = "5 Seconds";
            public string drep = "Off";

        //create the main tabs
        ButtonTree.ButtonNode tag = new ButtonTree.ButtonNode();
        ButtonTree.ButtonNode album = new ButtonTree.ButtonNode();
        ButtonTree.ButtonNode favorite = new ButtonTree.ButtonNode();
        ButtonTree.ButtonNode sort = new ButtonTree.ButtonNode();
        ButtonTree.ButtonNode share = new ButtonTree.ButtonNode();
        ButtonTree.ButtonNode print = new ButtonTree.ButtonNode();
        ButtonTree.ButtonNode options = new ButtonTree.ButtonNode();

        public Form1()
        {
            

            InitializeComponent();
            pictureAni.Hide();
            listView1.ShowItemToolTips = true;
            

            disableButton(backButton);
            disableButton(forwardButton);
            disableButton(redoButton);
            disableButton(undoButton);
     
             
            //create the secondary tabs
            ButtonTree.ButtonNode newTag = new ButtonTree.ButtonNode();

            ButtonTree.ButtonNode newAlbum = new ButtonTree.ButtonNode();
            //ButtonTree.ButtonNode allAlbum = new ButtonTree.ButtonNode();

            ButtonTree.ButtonNode threeStars = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode twoStars = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode oneStar = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode unrate = new ButtonTree.ButtonNode();

            ButtonTree.ButtonNode newestPictures = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode recentlyModified = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode abcTag = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode rating = new ButtonTree.ButtonNode();

            ButtonTree.ButtonNode email = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode usb = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode cd = new ButtonTree.ButtonNode();

            ButtonTree.ButtonNode fullSize = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode halfSize = new ButtonTree.ButtonNode();
            ButtonTree.ButtonNode photoSize = new ButtonTree.ButtonNode();

            ButtonTree.ButtonNode theme = new ButtonTree.ButtonNode();
             


            //add secondary tabs to the main tabs
            tag.AddChild(newTag);
           
            album.AddChild(newAlbum);
            //album.AddChild(allAlbum);

            favorite.AddChild(threeStars);
            favorite.AddChild(twoStars);
            favorite.AddChild(oneStar);
            favorite.AddChild(unrate);

            sort.AddChild(newestPictures);
            sort.AddChild(recentlyModified);
            sort.AddChild(abcTag);
            sort.AddChild(rating);

            share.AddChild(email);
            share.AddChild(usb);
            share.AddChild(cd);

            print.AddChild(fullSize);
            print.AddChild(halfSize);
            print.AddChild(photoSize);

            options.AddChild(theme);

            //add the pictures to the node buttons
            tag.NodeButton.Image = new Bitmap(Path.GetFullPath("tag.gif"));
            album.NodeButton.Image = new Bitmap(Path.GetFullPath("album.gif"));
            favorite.NodeButton.Image = new Bitmap(Path.GetFullPath("favorite.gif"));
            sort.NodeButton.Image = new Bitmap(Path.GetFullPath("sort.gif"));
            share.NodeButton.Image = new Bitmap(Path.GetFullPath("share.gif"));
            print.NodeButton.Image = new Bitmap(Path.GetFullPath("print.gif"));
            options.NodeButton.Image = new Bitmap(Path.GetFullPath("option.gif"));

            //add icons to subtabs and format them
            newTag.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("add tag.gif")), 60, 45);
         //   dragDropNodeButtons.Add(newTag.NodeButton); 
            newTag.NodeButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            newTag.NodeButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            newTag.NodeButton.BackColor = childButtonColor;

            newAlbum.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("add album.gif")), 50, 45);
            //dragDropNodeButtons.Add(newAlbum.NodeButton); 
            newAlbum.NodeButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            newAlbum.NodeButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            newAlbum.NodeButton.BackColor = childButtonColor;

            threeStars.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("3star.gif")), 65, 20);
            dragDropNodeButtons.Add(threeStars.NodeButton);
        

            twoStars.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("2star.gif")), 65, 20);
            dragDropNodeButtons.Add(twoStars.NodeButton);

            oneStar.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("1star.gif")), 65, 20);
            dragDropNodeButtons.Add(oneStar.NodeButton);

            unrate.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("no star.gif")), 65, 30);
            dragDropNodeButtons.Add(unrate.NodeButton);

            newestPictures.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("newest.gif")), 45, 45);
            dragDropNodeButtons.Add(newestPictures.NodeButton);

            recentlyModified.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("recently modified.gif")), 45, 45);
            dragDropNodeButtons.Add(recentlyModified.NodeButton);

            abcTag.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("alphabetically tag.gif")), 60, 25);
            dragDropNodeButtons.Add(abcTag.NodeButton);

            rating.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("highest.gif")), 55, 45);
            dragDropNodeButtons.Add(rating.NodeButton);

            email.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("email.gif")), 65, 45);
            email.NodeButton.Click += new System.EventHandler(this.email_Click);
            dragDropNodeButtons.Add(email.NodeButton);

            usb.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("usb.gif")), 65, 45);
            usb.NodeButton.Click += new System.EventHandler(this.usb_Click);
            dragDropNodeButtons.Add(usb.NodeButton);

            cd.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("burn.gif")), 45, 45);
            cd.NodeButton.Click += new System.EventHandler(this.burn_Click);
            dragDropNodeButtons.Add(cd.NodeButton);

            fullSize.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("full.gif")), 35, 45);
            fullSize.NodeButton.Click += new System.EventHandler(this.print1_Click);
            dragDropNodeButtons.Add(fullSize.NodeButton);

            halfSize.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("half.gif")), 35, 45);
            halfSize.NodeButton.Click += new System.EventHandler(this.print2_Click);
            dragDropNodeButtons.Add(halfSize.NodeButton);

            photoSize.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("photo.gif")), 50, 35);
            photoSize.NodeButton.Click += new System.EventHandler(this.print3_Click);
            dragDropNodeButtons.Add(photoSize.NodeButton);

            theme.NodeButton.Image = resizeImage(new Bitmap(Path.GetFullPath("theme.gif")), 50, 35);
            dragDropNodeButtons.Add(theme.NodeButton);

            //Iterate through all the Buttons on the secondary level.
            //The buttons are formatted and attached to an event handler for drag and drop
            foreach (Button secondaryBtn in dragDropNodeButtons)
            {
                secondaryBtn.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
                secondaryBtn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                secondaryBtn.BackColor = childButtonColor;
               // secondaryBtn.DragDrop += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragDrop);
                secondaryBtn.DragLeave += new System.EventHandler(this.buttonTree1_DragLeave);
                secondaryBtn.DragEnter += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragEnter);
                secondaryBtn.DragOver += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragOver);
                secondaryBtn.AllowDrop = true;
                secondaryBtn.Name = secondaryBtn.Text;

            }

            newestPictures.NodeButton.AllowDrop = false;
            recentlyModified.NodeButton.AllowDrop = false;
            abcTag.NodeButton.AllowDrop = false;
            rating.NodeButton.AllowDrop = false;
            theme.NodeButton.AllowDrop = false;

            parentNodeButtons.Add(tag.NodeButton);
            parentNodeButtons.Add(album.NodeButton);
            parentNodeButtons.Add(favorite.NodeButton);
            parentNodeButtons.Add(sort.NodeButton);
            parentNodeButtons.Add(share.NodeButton);
            parentNodeButtons.Add(print.NodeButton);
            parentNodeButtons.Add(options.NodeButton);

      

            //change node button background color
            reColorButtons();
          

            //label the text for the non specific node buttons

            newTag.NodeButton.Text = "NEW TAG";

            newAlbum.NodeButton.Text = "NEW ALBUM";
            //allAlbum.NodeButton.Text = "View All Photos";
            //allAlbum.NodeButton.Click += new System.EventHandler(this.allAlbum_Click);

            allAlbums.Add("ALL", new ArrayList());

            //For the favorites tab
            threeStars.NodeButton.Text = "3 Stars";
            threeStars.NodeButton.Name = "3";
            threeStars.NodeButton.Click += new System.EventHandler(this.ratings_Click);
            threeStars.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.rating_DragDrop);
            twoStars.NodeButton.Text = "2 Stars";
            twoStars.NodeButton.Name = "2";
            twoStars.NodeButton.Click += new System.EventHandler(this.ratings_Click);
            twoStars.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.rating_DragDrop);
            oneStar.NodeButton.Text = "1 Star";
            oneStar.NodeButton.Name = "1";
            oneStar.NodeButton.Click += new System.EventHandler(this.ratings_Click);
            oneStar.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.rating_DragDrop);
            unrate.NodeButton.Text = "UNRATE";
            unrate.NodeButton.Name = "0";
            unrate.NodeButton.Click += new System.EventHandler(this.ratings_Click);
            unrate.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.rating_DragDrop);

            newestPictures.NodeButton.Text = "NEWEST\nPICTURES";
            newestPictures.NodeButton.Click += new System.EventHandler(this.sortNewestPicture_Click);
            recentlyModified.NodeButton.Text = "MOST\nRECENTLY\nMODIFIED";
            recentlyModified.NodeButton.Click += new System.EventHandler(this.recentlyModified_Click);
            abcTag.NodeButton.Text = "ALPHA-\nBETICALLY";
            abcTag.NodeButton.Click += new System.EventHandler(this.sortAlpha_Click);
            rating.NodeButton.Text = "HIGHEST\nRATED";
            rating.NodeButton.Click += new System.EventHandler(this.favorites_Click);

            usb.NodeButton.Text = "USB";
            cd.NodeButton.Text = "COPY\nTO\nCD/DVD";
            email.NodeButton.Text = "EMAIL";

            fullSize.NodeButton.Text = "FULL PAGE";
            halfSize.NodeButton.Text = "HALF PAGE";
            photoSize.NodeButton.Text = "PHOTO SIZE";

            theme.NodeButton.Text = "THEME";
            theme.NodeButton.Click += new System.EventHandler(themeButton_Click);

            redrawTree();


            newTag.NodeButton.Click += new System.EventHandler(nodeButton_Click);
            newAlbum.NodeButton.Click += new System.EventHandler(newAlbumButton_Click);

            listView1.DoDragDrop(listView1.SelectedItems, DragDropEffects.Move);

            // Readjust some button images
            slideshowButton.Image = resizeImage(slideshowButton.Image, 40, 40);
            btn_browse.Image = resizeImage(btn_browse.Image, 60, 40);
            deleteButton.Image = resizeImage(deleteButton.Image, 40, 40);

            //secondaryBtn.DragDrop += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragDrop);
            email.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.openEmail);
            usb.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.openUsb);
            halfSize.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.openPrintHalf);
            fullSize.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.openPrintFull);
            photoSize.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.openPrintP);
            cd.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.openCD);
        }

        private void redrawTree()
        {
            this.buttonTree1.RemoveControls();

            this.buttonTree1.Add(tag);
            this.buttonTree1.Add(album);
            this.buttonTree1.Add(favorite);
            this.buttonTree1.Add(sort);
            this.buttonTree1.Add(share);
            this.buttonTree1.Add(print);
            this.buttonTree1.Add(options);


         //   listViewHistory.Add("All Pictures");
        }
        private void nodeButton_Click(object sender, System.EventArgs e)
        {
            newTag newTagForm = new newTag();

            newTagForm.ShowDialog();

            if (newTagForm.useTagName == true)
            {
                ButtonTree.ButtonNode newTagName = new ButtonTree.ButtonNode();
                newTagName.NodeButton.Text = newTagForm.tagName;
                tag.AddChild(newTagName);

                //format and add event handlers to the newly created button
                newTagName.NodeButton.Image = resizeImage(new Bitmap(Path.GetDirectoryName(Application.ExecutablePath).Replace("\\bin\\Debug", "\\Icons\\bucket.gif")), 50, 40);
                newTagName.NodeButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                newTagName.NodeButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
                newTagName.NodeButton.BackColor = childButtonColor;
                newTagName.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.tag_DragDrop);
                newTagName.NodeButton.DragLeave += new System.EventHandler(this.buttonTree1_DragLeave);
                newTagName.NodeButton.DragEnter += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragEnter);
                newTagName.NodeButton.DragOver += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragOver);
                
                newTagName.NodeButton.AllowDrop = true;
                newTagName.NodeButton.Name = newTagName.NodeButton.Text;
                newTagName.NodeButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tag_MouseDown);
                dragDropNodeButtons.Add(newTagName.NodeButton);
                newButtons.Add(newTagName.NodeButton);


                addNewTag(newTagName.NodeButton.Name);



                redrawTree();
                this.tag.Collapse();
                this.tag.Expand();
                lastActionText.Text = "You just created a new tag called: "+ newTagForm.tagName;
            }
        }

        private void newAlbumButton_Click(object sender, System.EventArgs e)
        {
            //show the new album form
            newAlbum newAlbumForm = new newAlbum();
            newAlbumForm.ShowDialog();


            if (newAlbumForm.useTagName == true && !newAlbumForm.tagName.Equals(""))
            {
                ButtonTree.ButtonNode newAlbumName = new ButtonTree.ButtonNode();
                newAlbumName.NodeButton.Text = newAlbumForm.tagName;
                album.AddChild(newAlbumName);
                addNewAlbum(newAlbumForm.tagName);

                //format and add event handlers to the newly created button
                newAlbumName.NodeButton.Image = resizeImage(new Bitmap(Path.GetDirectoryName(Application.ExecutablePath).Replace("\\bin\\Debug", "\\Icons\\bucket.gif")), 50, 40);
                newAlbumName.NodeButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                newAlbumName.NodeButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
                newAlbumName.NodeButton.BackColor = childButtonColor;
                newAlbumName.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.album_DragDrop);
                newAlbumName.NodeButton.DragLeave += new System.EventHandler(this.buttonTree1_DragLeave);
                newAlbumName.NodeButton.DragEnter += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragEnter);
                newAlbumName.NodeButton.DragOver += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragOver);
                newAlbumName.NodeButton.AllowDrop = true;
                newAlbumName.NodeButton.Name = newAlbumName.NodeButton.Text;
                newAlbumName.NodeButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.album_MouseDown);
                newButtons.Add(newAlbumName.NodeButton);
                dragDropNodeButtons.Add(newAlbumName.NodeButton);

                redrawTree();
                this.tag.Collapse();
                this.album.Collapse();
                this.album.Expand();
                lastActionText.Text = "You just created a new album called: " + newAlbumForm.tagName;
            }
 
        }

        public void reColorButtons()
        {
            foreach (Button btn in parentNodeButtons)
            {
                btn.BackColor = parentButtonColor;
            }
            foreach (Button btn in dragDropNodeButtons)
            {
                btn.BackColor = childButtonColor;
            }
        }


        private void import(object sender, EventArgs e)
        {
            deleteButton.Text = "Drag Pictures Here to Remove";
            imageList.ColorDepth = ColorDepth.Depth32Bit;


            string[] files = dlg.FileNames;
            string[] pathes = dlg.FileNames;

            trackNumItems.Add(pathes.Length);//mark6


          //only show the newly imported images
            listView1.Clear();
           int j = 0;

            foreach (string path in pathes)
            {
                System.Console.WriteLine(path);
            
                Image aImage = Bitmap.FromFile(path);

                //addImageToAlbum("ALL", browse);

                imageList.Images.Add(aImage);
                imageLocation.Add(path);
                FileInfo fileInfo = new FileInfo(path);
                String strDir = fileInfo.Name;

                imageCreatedList.Add(fileInfo.CreationTime);
                imageModifiedList.Add(fileInfo.LastWriteTime);
                imageFileNameList.Add(strDir);
                listView1.Items.Add(strDir);
                listView1.TileSize = new System.Drawing.Size(100, 80);
                //
                //make a tag entry for each image    
                allImageTags.Add(browse.ToString(), new ArrayList());
                //
                //make rating default of 0 for each new image
                allImageRatings.Add(browse.ToString(), 0);



                addNewImage(path);

                //add imageindex to display image.
                this.listView1.Items[j].ImageIndex = browse;           
                j++;
                browse++;
            }


            labelView.Text = "Very New Pictures";    //change the view label
            lastActionText.Text = "Very Nice Pictures";

            toolTipCreate();

            imageList.ImageSize = new Size(100, 80);
            this.listView1.View = View.LargeIcon;
            this.listView1.LargeImageList = imageList;
        }

        private void btn_browse_Click(object sender, System.EventArgs e)
        {
            dlg.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;" +

                               "*.jfif;*.png;*.tif;*.tiff;*.wmf;*.emf|" +

                        "Windows Bitmap (*.bmp)|*.bmp|" +

                        "Windows Icon (*.ico)|*.ico|" +

                        "Graphics Interchange Format (*.gif)|*.gif|" +

                        "JPEG File Interchange Format (*.jpg)|" +

                               "*.jpg;*.jpeg;*.jfif|" +

                        "Portable Network Graphics (*.png)|*.png|" +

                        "Tag Image File Format (*.tif)|*.tif;*.tiff|" +

                        "Windows Metafile (*.wmf)|*.wmf|" +

                        "Enhanced Metafile (*.emf)|*.emf|" +

                        "All Files (*.*)|*.*";

            dlg.InitialDirectory = @"C:\Users\Raymond\Pictures\2008-08-03 Janyon August 2, 08";
            dlg.Multiselect = true;

            try
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    import(sender, e);
                }
                dlg.Reset();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void toolTipCreate()
        {
            foreach (ListViewItem item in listView1.Items)
            {
                //image name
                item.ToolTipText = imageFileNameList[item.ImageIndex];

                //get tags associated with picture
                ArrayList tags = null;
                String tagString =""; 
                foreach (DictionaryEntry de in allImageTags)
                {
                    if (de.Key.Equals(item.ImageIndex.ToString()))
                    {
                         tags = (ArrayList)de.Value;
                    }
                }
                //transfer tags list into a string
                //
          
                    foreach (String s in tags)
                    {
                        tagString += s +", ";
                    }
                    if (tagString == "")
                    {
                        tagString = "none";
                    }
                
                item.ToolTipText += "\n\n Tags: " + tagString;

                //get album info
                String albumString = "";

                foreach (DictionaryEntry de in allAlbums)
                {
                    foreach (int i in (ArrayList)de.Value)
                    {
                        if (i == item.ImageIndex)
                        {
                            if(!de.Key.ToString().Equals("ALL"))
                            {
                                 albumString += de.Key.ToString() + ", ";
                            }
                        }
                    }
                }
                if (albumString == "")
                {
                    item.ToolTipText += "\n Albums: none";
                }
                else
                {
                    item.ToolTipText += "\n Albums: " + albumString;
                }

                //get favorites info and add to tooltip

                 foreach (DictionaryEntry de in allImageRatings)
                 {
                     if (de.Key.Equals(item.ImageIndex.ToString()))
                     {
                         if ((int)de.Value == 0)
                         {
                             item.ToolTipText += "\n Favorites Rating: Unrated";
                         }
                         else
                         {
                             item.ToolTipText += "\n Favorites Rating: " + (int)de.Value + " Stars";
                         }
                     }
                 }

                //add to tooltip of date modified and created
                 item.ToolTipText += "\n\n Last Modified: " + imageModifiedList[item.ImageIndex];
                 item.ToolTipText += "\n Date Created : " + imageCreatedList[item.ImageIndex];

            }

        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {

            // user clicked an item of listview control

            if (listView1.SelectedItems.Count > 0)
            {
                int index = listView1.SelectedItems[0].ImageIndex;
                int rating =0;
                ArrayList tags=null;
                foreach(DictionaryEntry de in allImageRatings)
                {
                    if(de.Key.Equals(index.ToString()))
                    {
                        rating = (int)de.Value;
                    }
                }
                        foreach(DictionaryEntry de in allImageTags)
                {
                    if(de.Key.Equals(index.ToString()))
                    {
                        tags = (ArrayList)de.Value;
                    }
                }
                EditView editViewForm = new EditView(imageLocation, listView1.SelectedItems[0], imageFileNameList[index], rating, tags, listView1.Items, this, formBackg );
                editViewForm.ShowDialog();
   
            }
        }



        //show slideshow options popup box
        private void slideshowButton_Click(object sender, EventArgs e)
        {
            List<string> slideShowImageLocations = new List<string>();

            foreach (ListViewItem lvi in listView1.Items)
            {
                slideShowImageLocations.Add(imageLocation[lvi.ImageIndex]);
            }

            slideShowOption sSoption = new slideShowOption(this, slideShowImageLocations);

            sSoption.ShowDialog();
        }



        public static Image resizeImage(Image aImage, int aWidth, int aHeight)
        {
            Bitmap aBitmap = new Bitmap(aWidth, aHeight);
            Graphics aGraphic = Graphics.FromImage((Image)aBitmap);

            aGraphic.DrawImage(aImage, 0, 0, aWidth, aHeight);

            return (Image)aBitmap;
        }

        //private void photoLayoutButton_Click(object sender, EventArgs e)
        //{
        //    if (layoutButtonMode == 0)
        //    {
        //        layoutButtonMode = 1;

        //        photoLayoutButton.BackgroundImage = new Bitmap(Path.GetFullPath("messy.gif"));
        //    }
        //    else if (layoutButtonMode == 1)
        //    {
        //        layoutButtonMode = 0;

        //        photoLayoutButton.BackgroundImage = new Bitmap(Path.GetFullPath("grid.gif"));
        //    }

        //}

        private void helpButton_Click(object sender, EventArgs e)
        {
            HelpMenu helpMenu = new HelpMenu();

            helpMenu.ShowDialog();
        }
        //mmmmark2
        public void addNewAlbum(String albumName)
        {
            newThing();

            if (!undoing && !redoing)
            {
                trackNumItems.Add(1);
            }

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                de.Key = "add album";
                de.Value = albumName;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }
            if (undoing || redoing)
            {
                ButtonTree.ButtonNode newAlbumName = new ButtonTree.ButtonNode();
                newAlbumName.NodeButton.Text = albumName;
                album.AddChild(newAlbumName);
      

                //format and add event handlers to the newly created button
                newAlbumName.NodeButton.Image = resizeImage(new Bitmap(Path.GetDirectoryName(Application.ExecutablePath).Replace("\\bin\\Debug", "\\Icons\\bucket.gif")), 50, 40);
                newAlbumName.NodeButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                newAlbumName.NodeButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
                newAlbumName.NodeButton.BackColor = childButtonColor;
                newAlbumName.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.album_DragDrop);
                newAlbumName.NodeButton.DragLeave += new System.EventHandler(this.buttonTree1_DragLeave);
                newAlbumName.NodeButton.DragEnter += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragEnter);
                newAlbumName.NodeButton.DragOver += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragOver);
                newAlbumName.NodeButton.AllowDrop = true;
                newAlbumName.NodeButton.Name = newAlbumName.NodeButton.Text;
                newAlbumName.NodeButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.album_MouseDown);
                newButtons.Add(newAlbumName.NodeButton);
                dragDropNodeButtons.Add(newAlbumName.NodeButton);

                redrawTree();
                this.tag.Collapse();
                this.album.Collapse();
                this.album.Expand();
             //   lastActionText.Text = "You just created a new album!";
            }


            if (allAlbums.ContainsKey(albumName))
            {
               // new ErrorAddingNewAlbum().ShowDialog();
                
            }
            else
            {


                if (undoing || redoing)
                {
                    allAlbums.Add(albumName, allErasedAlbums[albumName]);
                    allErasedAlbums.Remove(albumName);
                }
                else
                {
                    allAlbums.Add(albumName, new ArrayList());
                }
            }
        }

        public void removeAlbum(String albumName)
        {
            newThing();

            if (!undoing && !redoing)
            {
                trackNumItems.Add(1);
            }

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                de.Key = "remove album";
                de.Value = albumName;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }
            if (undoing || redoing)
            {
                foreach (ButtonTree.ButtonNode node in album)
                {
                    if (node.NodeButton.Text.Equals(albumName))
                    {
                        album.Remove(node);
                        redrawTree();
                        album.Collapse();
                        album.Expand();
                        break;
                    }
                }
                allAlbum_Click(null, null);
            }

            if (albumName == "ALL")
            {
                new ErrorRemovingALLAlbum().ShowDialog();
            }
            else
            {
                allErasedAlbums.Add(albumName, allAlbums[albumName]);
                allAlbums.Remove(albumName);
            }
        }


        public void addImageToAlbum(String albumName, int imageIndex)
        {
            newThing();

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                DictionaryEntry de2 = new DictionaryEntry();
                de.Key = "add photo to album";
                de2.Key = albumName;
                de2.Value = imageIndex;
                de.Value = de2;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }

            ArrayList albumImages = new ArrayList();

            foreach (DictionaryEntry de in allAlbums)
            {
                if (de.Key == albumName)
                {
                    albumImages = (ArrayList)de.Value;
                }
            }

            if (!albumImages.Contains(imageIndex))
            {
                albumImages.Add(imageIndex);

                if (undoing || redoing)
                {
                    foreach (Button b in dragDropNodeButtons)
                    {

                        if (b.Text == albumName)
                        {
                            MouseEventArgs mm = new MouseEventArgs(MouseButtons.XButton2, 0, 111111, 111111, 0);

                            album_MouseDown(b, mm);
                        }
                    }
                    //mmmark1
                }
            }
        }

        void newThing()
        {
            if (!undoing && !redoing)
            {

                if (undoHistory.Count > 0)
                {
                    trackNumItemsHistory.Clear();
                    undoHistory.Clear();
                    disableButton(redoButton);
                }
            }
        }

        public void removeImageFromAlbum(String albumName, int aImage)
        {
            newThing();

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                DictionaryEntry de2 = new DictionaryEntry();
                de.Key = "remove photo from album";
                de2.Key = albumName;
                de2.Value = aImage;
                de.Value = de2;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }

            ArrayList albumImages = new ArrayList();

            foreach (DictionaryEntry de in allAlbums)
            {
                if (de.Key.Equals(albumName))
                {
                    albumImages = (ArrayList)de.Value;
                }
            }

            albumImages.Remove(aImage);

            if (undoing || redoing)
            {
                foreach (Button b in dragDropNodeButtons)
                {

                    if (b.Text == albumName)
                    {
                        MouseEventArgs mm = new MouseEventArgs(MouseButtons.XButton2, 0, 111111, 111111, 0);

                        album_MouseDown(b, mm);
                    }
                }
            }
        }

        public void addTagToImage(String aTag, String aImage)
        {
            newThing();

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                DictionaryEntry de2 = new DictionaryEntry();
                de.Key = "add tag to image";
                de2.Key = aTag;
                de2.Value = aImage;
                de.Value = de2;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }

            ArrayList imageTags = new ArrayList();

            foreach (DictionaryEntry de in allImageTags)
            {
                if (aImage.Equals(de.Key))
                {
                    imageTags = (ArrayList)de.Value;
                }
            }

            if (!imageTags.Contains(aTag))
            {
                imageTags.Add(aTag);
            }

            if (undoing || redoing)
            {
                foreach (Button b in dragDropNodeButtons)
                {

                    if (b.Text == aTag)
                    {
                        MouseEventArgs mm = new MouseEventArgs(MouseButtons.XButton2, 0, 111111, 111111, 0);

                        tag_MouseDown(b, mm);
                    }
                }
            }
        }

        public void removeTagFromImage(String aTag, String aImage)
        {
            newThing();

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                DictionaryEntry de2 = new DictionaryEntry();
                de.Key = "remove tag from image";
                de2.Key = aTag;
                de2.Value = aImage;
                de.Value = de2;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }

            ArrayList imageTags = new ArrayList();

            foreach (DictionaryEntry de in allImageTags)
            {
                if (de.Key.Equals(aImage))
                {
                    imageTags = (ArrayList)de.Value;
                }
            }

            imageTags.Remove(aTag);

            if (undoing || redoing)
            {
                foreach (Button b in dragDropNodeButtons)
                {

                    if (b.Text == aTag)
                    {
                        MouseEventArgs mm = new MouseEventArgs(MouseButtons.XButton2, 0, 111111, 111111, 0);

                        tag_MouseDown(b, mm);
                    }
                }
            }
        }

        public void setImageRating(int rating, String aImage)
        {
            newThing();

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                DictionaryEntry de2 = new DictionaryEntry();
                DictionaryEntry de3 = new DictionaryEntry();
                de.Key = "set image rating";
                de2.Key = allImageRatings[aImage];
                de3.Key = rating;
                de3.Value = aImage;
                de2.Value = de3;
                de.Value = de2;
                actionHistory.Add(de);



                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }

            allImageRatings.Remove(aImage);
            allImageRatings.Add(aImage, rating);


            if (undoing || redoing)
            {
                foreach (Button b in dragDropNodeButtons)
                {
                    if (rating == 0)
                    {
                        if (b.Text.Contains("UNRATE"))
                        {
                            MouseEventArgs mm = new MouseEventArgs(MouseButtons.XButton2, 0, 111111, 111111, 0);

                            System.Console.WriteLine("dsfadf");


                            ratings_Click(b, mm);
                        }
                    }
                    else
                    {
                        if (b.Text.Contains(rating.ToString()))
                        {
                            MouseEventArgs mm = new MouseEventArgs(MouseButtons.XButton2, 0, 111111, 111111, 0);

                            System.Console.WriteLine("dsfadf");


                            ratings_Click(b, mm);
                        }
                    }


                }
            }
        }


        private void undoButton_Click(object sender, EventArgs e)
        {
            int times = trackNumItems[trackNumItems.Count-1];
            trackNumItems.Remove(trackNumItems.Count - 1);
            trackNumItemsHistory.Add(times);
            //System.Console.WriteLine("u: " + times);
            String word = null;

            for (int abc = 0; abc < times; abc++ )
            {

                undoing = true;

                if (actionHistory.Count > 0)
                {
                    DictionaryEntry de = (DictionaryEntry)actionHistory[actionHistory.Count - 1];
                    String action = (String)de.Key;

                    

                    undoHistory.Add(de);
                    actionHistory.Remove(de);

                    if (undoHistory.Count == 1)
                    {
                        enableButton(redoButton);
                    }

                    if (action == "add photo to album")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        removeImageFromAlbum((String)de2.Key, (int)de2.Value);


                        if (times == 1)
                        {
                            word = "You just undid adding 1 photo to ablum " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just undid adding " + times + " photos to ablum " + (String)de2.Key;
                        }
                    }
                    else if (action == "remove photo from album")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        addImageToAlbum((String)de2.Key, (int)de2.Value);

                        if (times == 1)
                        {
                            word = "You just undid removing 1 photo to ablum " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just undid removing " + times + " photos to ablum " + (String)de2.Key;
                        }
                    }
                    else if (action == "add album")
                    {
                        String albumName = (String)de.Value;

                        removeAlbum(albumName);



                        word = "You just undid adding album " + albumName;
                        
                    }
                    else if (action == "remove album")
                    {
                        String albumName = (String)de.Value;

                        addNewAlbum(albumName);

                        word = "You just undid removing album " + albumName;
                    }
                    else if (action == "add tag")
                    {
                        String albumName = (String)de.Value;

                        removeTag(albumName);

                        word = "You just undid adding tag " + albumName;
                    }
                    else if (action == "remove tag")
                    {
                        String albumName = (String)de.Value;

                        addNewTag(albumName);

                        word = "You just undid removing tag " + albumName;
                    }
                    else if (action == "add image")
                    {
                        String albumName = (String)de.Value;

                        removeImage(albumName);

                        if (times == 1)
                        {
                            word = "You just undid adding 1 photo ";
                        }
                        else
                        {

                            word = "You just undid adding " + times + " photos";
                        }
                    }
                    else if (action == "remove image")
                    {
                        String albumName = (String)de.Value;

                        addNewImage(albumName);

                        if (times == 1)
                        {
                            word = "You just undid removing 1 photo ";
                        }
                        else
                        {

                            word = "You just undid removing " + times + " photos";
                        }
                    }
                    else if (action == "add tag to image")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        removeTagFromImage((String)de2.Key, (String)de2.Value);

                        if (times == 1)
                        {
                            word = "You just undid adding 1 photo to tag " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just undid adding " + times + " photos to tag " + (String)de2.Key;
                        }
                    }
                    else if (action == "remove tag from image")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        addTagToImage((String)de2.Key, (String)de2.Value);

                        if (times == 1)
                        {
                            word = "You just undid removing 1 photo to tag " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just undid removing " + times + " photos to tag " + (String)de2.Key;
                        }
                    }
                    else if (action == "set image rating")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;
                        DictionaryEntry de3 = (DictionaryEntry)de2.Value;

                        // Note de3.Key is the new rating set
                        // and de2.Key is the old rating before the set

                        setImageRating((int)de2.Key, (String)de3.Value);

                        if (times == 1)
                        {
                            word = "You just undid setting 1 photo to " + (int)de3.Key + " stars";
                        }
                        else
                        {

                            word = "You just undid setting " + times + " photos to " + (int)de3.Key + " stars";
                        }
                    }

                    if (actionHistory.Count == 0)
                    {
                        disableButton(undoButton);
                    }

                    undoing = false;
                }
            }


            lastActionText.Text = word;
        }

        private void redoButton_Click(object sender, EventArgs e)
        {
            int times = trackNumItemsHistory[trackNumItemsHistory.Count - 1];
            trackNumItemsHistory.Remove(trackNumItemsHistory.Count - 1);
            trackNumItems.Add(times);
            //System.Console.WriteLine("r: " + times);

            String word = null;

            for (int abc = 0; abc < times; abc++)
            {



                redoing = true;

                if (undoHistory.Count > 0)
                {
                    DictionaryEntry de = (DictionaryEntry)undoHistory[undoHistory.Count - 1];
                    String action = (String)de.Key;

                    //Don't need since already done in called methods
                    //actionHistory.Add(de);
                    //if (actionHistory.Count == 0)
                    //{
                    //    enableButton(undoButton);
                    //}

                    undoHistory.Remove(de);

                    if (action == "add photo to album")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        addImageToAlbum((String)de2.Key, (int)de2.Value);

                        if (times == 1)
                        {
                            word = "You just redid adding 1 photo to ablum " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just redid adding " + times + " photos to ablum " + (String)de2.Key;
                        }
                    }
                    else if (action == "remove photo from album")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        removeImageFromAlbum((String)de2.Key, (int)de2.Value);

                        if (times == 1)
                        {
                            word = "You just redid removing 1 photo to ablum " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just redid removing " + times + " photos to ablum " + (String)de2.Key;
                        }
                    }
                    else if (action == "add album")
                    {
                        String albumName = (String)de.Value;

                        addNewAlbum(albumName);

                        word = "You just redid adding album " + albumName;
                    }
                    else if (action == "remove album")
                    {
                        String albumName = (String)de.Value;

                        removeAlbum(albumName);

                        word = "You just redid removing album " + albumName;
                    }
                    else if (action == "add tag")
                    {
                        String albumName = (String)de.Value;

                        addNewTag(albumName);

                        word = "You just redid adding tag " + albumName;
                    }
                    else if (action == "remove tag")
                    {
                        String albumName = (String)de.Value;

                        removeTag(albumName);

                        word = "You just redid removing tag " + albumName;
                    }
                    else if (action == "add image")
                    {
                        String albumName = (String)de.Value;

                        addNewImage(albumName);

                        if (times == 1)
                        {
                            word = "You just redid adding 1 photo ";
                        }
                        else
                        {

                            word = "You just redid adding " + times + " photos";
                        }
                    }
                    else if (action == "remove image")
                    {
                        String albumName = (String)de.Value;

                        removeImage(albumName);

                        if (times == 1)
                        {
                            word = "You just redid removing 1 photo ";
                        }
                        else
                        {

                            word = "You just redid removing " + times + " photos";
                        }
                    }
                    else if (action == "add tag to image")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        addTagToImage((String)de2.Key, (String)de2.Value);

                        if (times == 1)
                        {
                            word = "You just redid adding 1 photo to tag " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just redid adding " + times + " photos to tag " + (String)de2.Key;
                        }
                    }
                    else if (action == "remove tag from image")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;

                        removeTagFromImage((String)de2.Key, (String)de2.Value);

                        if (times == 1)
                        {
                            word = "You just redid removing 1 photo to tag " + (String)de2.Key;
                        }
                        else
                        {

                            word = "You just redid removing " + times + " photos to tag " + (String)de2.Key;
                        }
                    }
                    else if (action == "set image rating")
                    {
                        DictionaryEntry de2 = (DictionaryEntry)de.Value;
                        DictionaryEntry de3 = (DictionaryEntry)de2.Value;

                        // Note de3.Key is the new rating set
                        // and de2.Key is the old rating before the set

                        setImageRating((int)de3.Key, (String)de3.Value);

                        if (times == 1)
                        {
                            word = "You just redid setting 1 photo to " + (int)de3.Key + " stars";
                        }
                        else
                        {

                            word = "You just redid setting " + times + " photos to " + (int)de3.Key + " stars";
                        }

                    }

                    if (undoHistory.Count == 0)
                    {
                        disableButton(redoButton);
                    }

                    redoing = false;
                }
            }

            lastActionText.Text = word;
        }

        private void disableButton(Button aButton)
        {
            aButton.Enabled = false;
            buttonImages.Add(aButton.Name, aButton.BackgroundImage);
            aButton.BackgroundImage = MakeGrayscale(new Bitmap(aButton.BackgroundImage));
        }

        private void enableButton(Button aButton)
        {
            aButton.Enabled = true;
            aButton.BackgroundImage = (Image) buttonImages[aButton.Name];
            buttonImages.Remove(aButton.Name);
        }

        private void disableButton1(Button aButton)
        {
            aButton.Enabled = false;
            buttonImages.Add(aButton.Name, aButton.Image);
            aButton.Image = MakeGrayscale(new Bitmap(aButton.Image));
        }

        private void enableButton1(Button aButton)
        {
            aButton.Enabled = true;
            aButton.Image = (Image)buttonImages[aButton.Name];
            buttonImages.Remove(aButton.Name);
        }

        // From
        // http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale
        public static Bitmap MakeGrayscale(Bitmap original)
        {
            //make an empty bitmap the same size as original
            Bitmap newBitmap = new Bitmap(original.Width, original.Height);

            for (int i = 0; i < original.Width; i++)
            {
                for (int j = 0; j < original.Height; j++)
                {
                    //get the pixel from the original image
                    Color originalColor = original.GetPixel(i, j);

                    //create the grayscale version of the pixel
                    int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
                        + (originalColor.B * .11));

                    //create the color object
                    Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);

                    //set the new image's pixel to the grayscale version
                    newBitmap.SetPixel(i, j, newColor);
                }
            }

            return newBitmap;
        }


        #region Form drag handlers

        //
        // These provide a drag image while dragging over the Form
        //

        protected override void OnDragEnter(DragEventArgs drgevent)
        {
            DropTargetHelper.DragEnter(this, drgevent.Data, new Point(drgevent.X, drgevent.Y), DragDropEffects.None);
            base.OnDragEnter(drgevent);
        }

        protected override void OnDragOver(DragEventArgs drgevent)
        {
            DropTargetHelper.DragOver(new Point(drgevent.X, drgevent.Y), DragDropEffects.None);
            base.OnDragOver(drgevent);
        }

        protected override void OnDragLeave(EventArgs e)
        {
            DropTargetHelper.DragLeave(this);
            base.OnDragLeave(e);
        }

        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            DropTargetHelper.Drop(drgevent.Data, new Point(drgevent.X, drgevent.Y), DragDropEffects.None);
            base.OnDragDrop(drgevent);
        }

        #endregion // Form drag handlers


        #region Drag and Drop Handlers

        //
        // These provide a drag image while dragging over the Form
        //

        private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
          ArrayList files = new ArrayList();
			foreach(ListViewItem lvi in listView1.SelectedItems)
            {files.Add("test");
            //MessageBox.Show(lvi.ImageKey);
            }
			DataObjectEx data = new DataObjectEx();
			data.SetData(DataFormats.Text, (string[])files.ToArray(typeof(string)));
            Color col = deleteButton.BackColor;
            deleteButton.BackColor = Color.Red;
            foreach (Button btn in newButtons)
            {
                btn.Image = resizeImage(new Bitmap(Path.GetDirectoryName(Application.ExecutablePath).Replace("\\bin\\Debug", "\\Icons\\in bucket.gif")), 75, 40);
            }

			DragDropEffects res = ShellUtils.DragSource.DoDragDrop(data, listView1, DragDropEffects.Copy | DragDropEffects.Move, PointToClient(MousePosition));
            deleteButton.BackColor = col;
            foreach (Button btn in newButtons)
            {
                btn.Image = resizeImage(new Bitmap(Path.GetDirectoryName(Application.ExecutablePath).Replace("\\bin\\Debug", "\\Icons\\bucket.gif")), 50, 40);
            }
            
        }

        private void buttonTree1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            DropTargetHelper.DragEnter(tag.NodeButton, e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = parentButtonColor;

            }
            catch
            {
                MessageBox.Show("error1");
            }
       
 
        }

        private void buttonTree1_DragLeave(object sender, EventArgs e)
        {
            DropTargetHelper.DragLeave(tag.NodeButton);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;

            }
            catch
            {
                MessageBox.Show("error2");
            }
        }

        private void album_DragDrop(object sender, DragEventArgs e)
        {
            
            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    addImageToAlbum(btn.Text, pic.ImageIndex);
                }
               trackNumItems.Add(listView1.SelectedItems.Count);
               if (listView1.SelectedItems.Count == 1)
               {
                   lastActionText.Text = "A picture was just added to the album:" + btn.Text;
               }
               else
               {
                   lastActionText.Text = listView1.SelectedItems.Count + " pictures were just added to the album: " + btn.Text;
               }
            }
            catch
            {
                MessageBox.Show("error3");
            }
         
            toolTipCreate();

        }

        private void tag_DragDrop(object sender, DragEventArgs e)
        {
            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    addTagToImage(btn.Text, pic.ImageIndex.ToString());
                }
                trackNumItems.Add(listView1.SelectedItems.Count);
                if (listView1.SelectedItems.Count == 1)
                {
                    lastActionText.Text = "One of your pictures was just tagged as: " + btn.Text;
                }
                else
                {
                    lastActionText.Text = listView1.SelectedItems.Count + " pictures were tagged as: " + btn.Text;
                }
            }
            catch
            {
                MessageBox.Show("error3");
            }
            toolTipCreate();
        }

        private void rating_DragDrop(object sender, DragEventArgs e)
        {
            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    int rating = Int32.Parse(btn.Name);
                    setImageRating(rating, pic.ImageIndex.ToString());
                }
                trackNumItems.Add(listView1.SelectedItems.Count);
                if (listView1.SelectedItems.Count == 1)
                {
                    lastActionText.Text = "You made one of your pictures a " + btn.Text +" favorite!";
                }
                else
                {
                    lastActionText.Text = listView1.SelectedItems.Count + " your pictures were made as " + btn.Text + " favorite!";
                }
            }
            catch
            {
                MessageBox.Show("error3");
            }
            toolTipCreate();
        }

        private void buttonTree1_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            DropTargetHelper.DragOver(new Point(e.X, e.Y), e.Effect);
        }

        private void backButton_Click(object sender, EventArgs e)
        {
            backing = true;

            if (listViewHistory.Count > 0)
            {
                //string view = (string) listViewHistory[listViewHistory.Count-2];

                /*
                if (view == "All Pictures")
                {
                    allAlbum_Click(null, null);
                }
                */

                DictionaryEntry view = (DictionaryEntry)listViewHistory[listViewHistory.Count - 1];


                labelView.Text = (string) view.Key;
                listView1.Clear();


                int i = 0;

                ArrayList a = (ArrayList)view.Value;

                try
                {
                    foreach (object imageIndex in a)
                    {
                        listView1.Items.Add(imageFileNameList[(int)imageIndex]);
                        listView1.Items[i].ImageIndex = (int)imageIndex;
                        i++;
                    }
                }
                catch (Exception eeee) { }


                listViewHistory.RemoveAt(listViewHistory.Count - 1);
                backHistory.Add(theView);
                theView = view;

                if (backHistory.Count == 1)
                {
                    enableButton(forwardButton);
                }

                if (listViewHistory.Count == 0)
                {
                    disableButton(backButton);
                }
            }

            toolTipCreate();

            backing = false;
        }

        private void forwardButton_Click(object sender, EventArgs e)
        {
            forwarding = true;

            if (backHistory.Count > 0)
            {
                //List<string> imageLocationsList = (List<string>) backHistory[backHistory.Count - 1];

                //listViewRefresh(imageLocationsList);

                //string view = (string)backHistory[backHistory.Count - 1];


                DictionaryEntry view = (DictionaryEntry)backHistory[backHistory.Count - 1];


                labelView.Text = (string)view.Key;
                listView1.Clear();


                int i = 0;

                ArrayList a = (ArrayList)view.Value;

                foreach (object imageIndex in a)
                {
                    listView1.Items.Add(imageFileNameList[(int)imageIndex]);
                    listView1.Items[i].ImageIndex = (int)imageIndex;
                    i++;
                }


                backHistory.RemoveAt(backHistory.Count - 1);
                listViewHistory.Add(theView);
                theView = view;

                if (listViewHistory.Count == 1)
                {
                    enableButton(backButton);
                }

                if (backHistory.Count == 0)
                {
                    disableButton(forwardButton);
                }
            }

            toolTipCreate();

            forwarding = false;
        }

        private void listViewRefresh(List<string> imageLocationsList)
        {
            browse = 0;
            imageList = new ImageList();
            imageList.ColorDepth = ColorDepth.Depth32Bit;
            imageLocation.Clear();
            listView1.Items.Clear();

            foreach (string path in imageLocationsList)
            {
                System.Console.WriteLine(path);
                Image aImage = Bitmap.FromFile(path);
                imageList.Images.Add(aImage);
                imageLocation.Add(path);
                FileInfo fileInfo = new FileInfo(path);
                String strDir = fileInfo.Name;
                listView1.Items.Add(strDir);
                listView1.TileSize = new System.Drawing.Size(100, 80);
                browse++;
            }

            for (int j = 0; j < browse; j++)
            {
                this.listView1.Items[j].ImageIndex = j;
            }


            imageList.ImageSize = new Size(100, 80);
            this.listView1.View = View.LargeIcon;
            this.listView1.LargeImageList = imageList;
        }

        Button tempGlobalButton;
        bool tagWasDragged = false;

        private void album_MouseDown(object sender, MouseEventArgs e)
        {

            try
            {

                Button btnClicked = (Button)sender;
                listView1.Clear();
                labelView.Text = btnClicked.Text + " Album";     //change the view label
                whichAlbumToDelete = btnClicked.Text;

                ArrayList albumImages = new ArrayList();
                foreach (DictionaryEntry de in allAlbums)
                {
                    if (de.Key == btnClicked.Text)
                    {
                        albumImages = (ArrayList)de.Value;
                    }
                }
                int i = 0;
                foreach (int imageIndex in albumImages)
                {
                    listView1.Items.Add(imageFileNameList[imageIndex]);
                    listView1.Items[i].ImageIndex = imageIndex;
                    i++;
                }
            }
            catch
            {
                MessageBox.Show("error with albums");
            }

            //drag and drop stuff
            tempGlobalButton = (Button)sender;
            Color col = deleteButton.BackColor;
            deleteButton.BackColor = System.Drawing.Color.Red;
            deleteButton.Text = "Remove This Album";
            DragSourceHelper.DoDragDrop((Button)sender, new Point(e.X, e.Y), DragDropEffects.Copy);
            deleteButton.Text = "Remove Picture From Album";
            deleteButton.BackColor = col;
            //end drag and drop stuff

            toolTipCreate();

        }
        private void tag_MouseDown(object sender, MouseEventArgs e)
        {
            listView1.AllowDrop = true;
            foreach (Button btn in dragDropNodeButtons)
            {
                btn.AllowDrop = false;
            }

            
            try
            {
                Button btnClicked = (Button)sender;
                whichTagToDelete = btnClicked.Text;
            }catch{
            }

            //drag and drop stuff
            tempGlobalButton = (Button)sender;
            Color col = deleteButton.BackColor;
            deleteButton.BackColor = System.Drawing.Color.Red;
            deleteButton.Text = "Remove This Tag";
            DragSourceHelper.DoDragDrop((Button)sender, new Point(e.X, e.Y), DragDropEffects.Copy);
            deleteButton.BackColor = col;
            deleteButton.Text = "Remove Tag From Picture";
            //end of drag and drop stuff

            //display all tagged images
            if (tagWasDragged == false)
            {
                   
            try
            {
                Button btnClicked = (Button)sender;
                listView1.Clear();
                labelView.Text = "Tagged Pictures Of " + btnClicked.Text;     //change the view label
                whichTagToDelete = btnClicked.Text;

                ArrayList taggedImages = new ArrayList();
                foreach (DictionaryEntry de in allImageTags)
                {
                    ArrayList taggedList = (ArrayList)de.Value;
                    foreach (String tag in taggedList)
                    {
                        if (tag == btnClicked.Text)
                        {
                            int index = Int32.Parse((String)de.Key);
                            taggedImages.Add(index);
                        }
                    }
                }
                int i = 0;

                foreach (int imageIndex in taggedImages)
                {
                    listView1.Items.Add(imageFileNameList[imageIndex]);
                    listView1.Items[i].ImageIndex = imageIndex;
                    i++;
                }
            }
            catch
            {
                MessageBox.Show("error with tags");
            }
           
            }
            tagWasDragged = false;
            //
            //
            //drag drop properties of other controls
            foreach (Button btn in dragDropNodeButtons)
            {
                btn.AllowDrop = true;
            }
            listView1.AllowDrop = false;
           
            toolTipCreate();

        }

        private void deleteButton_DragDrop(object sender, DragEventArgs e)
        {
            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            if (deleteButton.Text == "Remove This Album")
            {
                foreach (ButtonTree.ButtonNode node in album)
                {
                    if (node.NodeButton.Text.Equals(tempGlobalButton.Text))
                    {
                        album.Remove(node);
                        redrawTree();
                        tag.Collapse();
                        tag.Expand();
                        album.Collapse();
                        album.Expand();
                        removeAlbum(node.NodeButton.Text);
                        break;
                    }
                }
                allAlbum_Click(null, null);
                lastActionText.Text = "The album: " + tempGlobalButton.Text + " has been removed";
            }
            else if (deleteButton.Text == "Remove This Tag")
            {

                foreach (ButtonTree.ButtonNode node in tag)
                {
                    if (node.NodeButton.Text.Equals(tempGlobalButton.Text))
                    {
                        tag.Remove(node);
                        redrawTree();
                        tag.Collapse();
                        tag.Expand();
                        allImageTags.Remove(node.NodeButton.Text);
                        Hashtable tempAllImageTags = new Hashtable();

                        foreach (DictionaryEntry de in allImageTags)
                        {
                            ArrayList alltags = (ArrayList)de.Value;
                            foreach (String s in alltags)
                            {

                                if (s.Equals(node.NodeButton.Text))
                                {
                                    ArrayList tempAllTags = new ArrayList();
                                    foreach (String ss in alltags)
                                    {
                                        tempAllTags.Add(ss);
                                    }
                                    tempAllTags.Remove(s);
                                    String key = (String)de.Key;
                                    tempAllImageTags.Add(key, tempAllTags);
                                }
                            }

                        }
                        foreach (DictionaryEntry de in tempAllImageTags)
                        {
                            allErasedTags.Add(de.Key, allImageTags[de.Key]);
                            //mark5
                            allImageTags.Remove(de.Key);
                            allImageTags.Add(de.Key, de.Value);
                        }
                        removeTag(node.NodeButton.Text);
                        break;
                    }
                }
                allAlbum_Click(null, null);
                lastActionText.Text = "The " + tempGlobalButton.Text + " tag has been removed";
            }
            else if (deleteButton.Text == "Remove Tag From Picture")
            {
                foreach (ListViewItem lvi in listView1.SelectedItems)
                {
                    removeTagFromImage(whichTagToDelete, lvi.ImageIndex.ToString());
                    lvi.Remove();
                }
                lastActionText.Text = "The " + whichTagToDelete+ " tag has been removed from your picture(s)";
            }
            else if (deleteButton.Text == "Remove Picture From Album")
            {
                foreach (ListViewItem lvi in listView1.SelectedItems)
                {
                    removeImageFromAlbum(whichAlbumToDelete, lvi.ImageIndex);
                    lvi.Remove();
                }
                lastActionText.Text = "Your picture(s) have been removed from the " + whichAlbumToDelete + " album";
            }
            else if (deleteButton.Text == "Drag Pictures Here to Remove")
            {
                int number = listView1.SelectedItems.Count;

                trackNumItems.Add(number);

                foreach (ListViewItem lvi in listView1.SelectedItems)
                {
                   // updateStuff(lvi.ImageIndex);
                    removeImage(imageLocation[lvi.ImageIndex]);

                    imageFileNameList.RemoveAt(lvi.ImageIndex);
                    imageCreatedList.RemoveAt(lvi.ImageIndex);
                    imageModifiedList.RemoveAt(lvi.ImageIndex);
                    imageLocation.RemoveAt(lvi.ImageIndex);
                    imageList.Images.RemoveAt(lvi.ImageIndex);
                    lvi.Remove();
                }
                lastActionText.Text =  number + " of your pictures have been completely removed";
            }

        }

        private void deleteButton_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            DropTargetHelper.DragEnter(tag.NodeButton, e.Data, new Point(e.X, e.Y), e.Effect);
            deleteButton.BackColor = Color.Beige;

        }

        private void deleteButton_DragLeave(object sender, EventArgs e)
        {
            DropTargetHelper.DragLeave(deleteButton);
            deleteButton.BackColor = Color.Red;
        }

        private void deleteButton_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            DropTargetHelper.DragOver(new Point(e.X, e.Y), e.Effect);
        }

        private void viewAllPhotos_Click(object sender, EventArgs e)
        {
            allAlbum_Click(null, null);
        }

        private void listView1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            DropTargetHelper.DragEnter(tag.NodeButton, e.Data, new Point(e.X, e.Y), e.Effect);
        }
        private void listView1_DragLeave(object sender, EventArgs e)
        {
            DropTargetHelper.DragLeave(listView1);
        }
        private void listView1_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            DropTargetHelper.DragOver(new Point(e.X, e.Y), e.Effect);
        }
        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            tagWasDragged = true;
            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            Point cp = listView1.PointToClient(new Point(e.X, e.Y));

            ListViewItem iIndex = listView1.GetItemAt(cp.X, cp.Y);
            
            addTagToImage(whichTagToDelete, iIndex.ImageIndex.ToString());
            
        }

        #endregion // Form drag handlers

        #region click handling for button tabs

        //
        // click handling for button tabs.
        //
        private void allAlbum_Click(object sender, EventArgs e)
        {
            labelView.Text = "All Pictures";   //change the view label
            deleteButton.Text = "Drag Pictures Here to Remove";
            listView1.Clear();
            for (int i = 0; i < imageList.Images.Count; i++)
            {
                listView1.Items.Add(imageFileNameList[i]);
                listView1.Items[i].ImageIndex = i;
             
            }
            toolTipCreate();
        }




        private void ratings_Click(object sender, EventArgs e)
        {
            try
            {
                Button btnClicked = (Button)sender;
                listView1.Clear();
                labelView.Text = btnClicked.Text + " Pictures";     //change the view label

                ArrayList ratedImages = new ArrayList();
                foreach (DictionaryEntry de in allImageRatings)
                {
                    String rate = btnClicked.Name;
                    String rate2 = de.Value.ToString();
                        if (rate.Equals(rate2))
                        {
                            int index = Int32.Parse(de.Key.ToString());
                            ratedImages.Add(index);
                        }
                    
                }
                int i = 0;

                foreach (int imageIndex in ratedImages)
                {
                    listView1.Items.Add(imageFileNameList[imageIndex]);
                    listView1.Items[i].ImageIndex = imageIndex;
                    i++;
                }
            }
            catch
            {
           
            }
            toolTipCreate();
        }


        private void sortNewestPicture_Click(object sender, EventArgs e)
        {
            labelView.Text = "Newest Added Pictures";
            List<int> reverseImageIndex = new List<int>();
            foreach (ListViewItem lvi in listView1.Items)
            {
                reverseImageIndex.Add(lvi.ImageIndex);
            }
            reverseImageIndex.Sort();
            reverseImageIndex.Reverse();
              
            listView1.Clear();
            int i = 0;
            foreach(int index in reverseImageIndex)
            {
                listView1.Items.Add(imageFileNameList[index]);
                listView1.Items[i].ImageIndex = reverseImageIndex[i];
                i++;

            }
            toolTipCreate();
        }



        private void recentlyModified_Click(object sender, EventArgs e)
        {
            labelView.Text = "Most Recently Updated Pictures";
            ListView.ListViewItemCollection oldOrder;
            oldOrder = listView1.Items;
            Hashtable nameToIndex = new Hashtable();
            List<DateTime> modDate = new List<DateTime>();
            List<DateTime> tempModDate = new List<DateTime>();
            foreach (DateTime dt in imageModifiedList)
            {
                modDate.Add(dt);
            }
            foreach (DateTime dt in imageModifiedList)
            {
                tempModDate.Add(dt);
            }

            modDate.Sort();
            modDate.Reverse();

            int i = 0;
            listView1.Clear();

            foreach (DateTime time in modDate)
            {
                int j = 0;
                foreach (DateTime time2 in imageModifiedList)
                {
                    
                    if (time == tempModDate[j])
                    {
                        listView1.Items.Add(imageFileNameList[j]);
                        listView1.Items[i].ImageIndex = j;
                        i++;
                        tempModDate.Remove(tempModDate[j]);
                        tempModDate.Insert(j, new DateTime());
                        break;
                    }
                    j++;
                }
            }
            toolTipCreate();
        }

        private void favorites_Click(object sender, EventArgs e)
        {
            labelView.Text = "Most Favorite Pictures";
            List<int> three = new List<int>();
            List<int> two = new List<int>();
            List<int> one = new List<int>();
            List<int> zero = new List<int>();
            foreach (ListViewItem lvi in listView1.Items)
            {
                foreach (DictionaryEntry de in allImageRatings)
                {
                    if (lvi.ImageIndex.ToString() == (String)de.Key)
                    {
                        if ((int)de.Value == 3)
                            three.Add(lvi.ImageIndex);
                        if ((int)de.Value == 2)
                            two.Add(lvi.ImageIndex);
                        if ((int)de.Value == 1)
                            one.Add(lvi.ImageIndex);
                        if ((int)de.Value == 0)
                            zero.Add(lvi.ImageIndex);
                    }
                }
              

            }
         
            listView1.Clear();

            int count = 0;
            foreach (int i in three)
            {
                listView1.Items.Add(imageFileNameList[i]);
                listView1.Items[count].ImageIndex = i;
                count++;
            }
            foreach (int i in two)
            {
                listView1.Items.Add(imageFileNameList[i]);
                listView1.Items[count].ImageIndex = i;
                count++;
            }
            foreach (int i in one)
            {
                listView1.Items.Add(imageFileNameList[i]);
                listView1.Items[count].ImageIndex = i;
                count++;
            }
            foreach (int i in zero)
            {
                listView1.Items.Add(imageFileNameList[i]);
                listView1.Items[count].ImageIndex = i;
                count++;
            }

            toolTipCreate();
        }

        private void sortAlpha_Click(object sender, EventArgs e)
        {
            labelView.Text = "Pictures in Alphabetical Order";
            ListView.ListViewItemCollection oldOrder ;
            oldOrder = listView1.Items;
            Hashtable nameToIndex = new Hashtable();
            ArrayList names = new ArrayList();
     
            foreach (ListViewItem lvi in oldOrder)
            {
                nameToIndex.Add(lvi.Text, lvi.ImageIndex);
                names.Add(lvi.Text);
            }
            names.Sort();
            int i = 0;
            listView1.Clear();

            foreach(String name in names)
            {
                listView1.Items.Add(name);
                foreach (DictionaryEntry de in nameToIndex)
                {
                    if (name == (String)de.Key)
                    {
                        listView1.Items[i].ImageIndex = (int)de.Value;
                        i++;
                    }
                }
            }


            toolTipCreate();
        }
        #endregion

       

        private bool mBusy;   // Busy changing text
        private List<String> searchItems;

        private void searchBox_TextChanged(object sender, EventArgs e)
        {
            labelView.Text = "Search for: " + searchBox.Text;
            int i = 0;
            string[] mSelections = searchItems.ToArray();
            listView1.Clear();
            if ( mBusy) return;
            if (searchBox.Text.Length == 0)
            {
                foreach (string s in mSelections)
                {
                    listView1.Items.Add(s);
                    listView1.Items[i].ImageIndex = imageFileNameList.IndexOf(s);
                    i++;
                }
            }
            else
            {
                try
                {
                    mBusy = true;      // Avoid running this code when we change the text 
                    foreach (string s in mSelections)
                    {
                        if (s.IndexOf(searchBox.Text, StringComparison.CurrentCultureIgnoreCase) != -1)
                        {
                            listView1.Items.Add(s);
                            listView1.Items[i].ImageIndex = imageFileNameList.IndexOf(s);
                            i++;

                        }
                    }
                }
                finally
                {
                    mBusy = false;
                }
            }
            toolTipCreate();
        }

        private void searchBox_Click(object sender, EventArgs e)
        {
            searchItems = new List<string>();
            foreach (ListViewItem lvi in listView1.Items)
            {
                searchItems.Add(lvi.Text);
            }
        }



        private void email_Click(object sender, EventArgs e)
        {
            toolTipClick.Show("Drag Pictures Here to Email", dragDropNodeButtons.ElementAt(8), 2000);
        }
        private void usb_Click(object sender, EventArgs e)
        {
            toolTipClick.Show("Drag Pictures Here to add to USB", dragDropNodeButtons.ElementAt(9), 2000);
        }
        private void burn_Click(object sender, EventArgs e)
        {
            toolTipClick.Show("Drag Pictures Here to Burn onto CD/DVD", dragDropNodeButtons.ElementAt(10), 2000);
        }
        private void print1_Click(object sender, EventArgs e)
        {
            toolTipClick.Show("Drag Pictures Here to Print Full Sized Images", dragDropNodeButtons.ElementAt(11), 2000);
        }
        private void print2_Click(object sender, EventArgs e)
        {
            toolTipClick.Show("Drag Pictures Here to Print Half Sized Images", dragDropNodeButtons.ElementAt(12), 2000);
        }
        private void print3_Click(object sender, EventArgs e)
        {
            toolTipClick.Show("Drag Pictures Here to Print Photo Sized Images", dragDropNodeButtons.ElementAt(13), 2000);
        }



        public static Image mergeImages(Image aImage, Image arrow, int arrowStartX, int arrowStartY)
        {
            Bitmap overlay_image = new Bitmap(arrow);
            Bitmap original_image = new Bitmap(aImage);

            Graphics g_original = Graphics.FromImage(original_image);
            g_original.DrawImage(overlay_image, arrowStartX, arrowStartY);

            return (Image)original_image;
        }

        private void labelView_TextChanged(object sender, EventArgs e)
        {






   //         if (firstrun == false)
     //       {
       //         firstrun = false;
        //    }
         //   else
           // {

                if (!backing)
                {
                    if (!forwarding)
                    {
                        if (!labelView.Text.Contains("."))
                        {
                        activityTimer.Tick += activityWorker_Tick;
                        activityTimer.Interval = 11;
                        activityTimer.Enabled = true;
                        }
                    }
                }
        //    }
        }

        void activityWorker_Tick(object sender, EventArgs e)
        {
            if (firstrun == false)
            {
                listViewHistory.Add(theView);
            }
            else
            {
                firstrun = false;
            }

            ArrayList ne = new ArrayList();

            foreach (ListViewItem ii in listView1.Items)
            {
                ne.Add(ii.ImageIndex);
            }

            theView = new DictionaryEntry(labelView.Text, ne);

//            System.Console.WriteLine(listViewHistory.Count);

            activityTimer.Enabled = false;
            activityTimer = new System.Windows.Forms.Timer();

            if (listViewHistory.Count == 1)
            {
                enableButton(backButton);
            }

            backHistory.Clear();
            if (forwardButton.Enabled == true)
            {
                disableButton(forwardButton);
            }
        }

        private void openEmail(object sender, DragEventArgs e)
        {
            ArrayList aaa = new ArrayList();

            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    aaa.Add(pic.ImageIndex);
                }

            }
            catch
            {
                MessageBox.Show("error3");
            }

            EMail a = new EMail(this, aaa);

            a.ShowDialog();
        }

        private void openUsb(object sender, DragEventArgs e)
        {
            ArrayList aaa = new ArrayList();

            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    aaa.Add(pic.ImageIndex);
                }

            }
            catch
            {
                MessageBox.Show("error3");
            }

            UsbWindow a = new UsbWindow(this, aaa);

            a.ShowDialog();
        }


        private void openPrintHalf(object sender, DragEventArgs e)
        {
            ArrayList aaa = new ArrayList();

            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    aaa.Add(pic.ImageIndex);
                }

            }
            catch
            {
                MessageBox.Show("error3");
            }

            PrintPreview a = new PrintPreview(this, aaa, 1);

            a.ShowDialog();
        }

        private void themeButton_Click(object sender, EventArgs e)
        {
            Theme themeForm = new Theme(this);

     
                themeForm.ShowDialog();
                Color parentBtn = parentButtonColor;
                Color childBtn = childButtonColor;
                Color formBackground = Form1.DefaultBackColor;

                parentButtonColor = themeForm.parentBtn;
                childButtonColor = themeForm.childBtn;
                Form1.ActiveForm.BackColor = themeForm.formBackground;
                formBackg = themeForm.formBackground;
                reColorButtons();
            

        }

      




        private void openPrintFull(object sender, DragEventArgs e)
        {
            ArrayList aaa = new ArrayList();

            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    aaa.Add(pic.ImageIndex);
                }

            }
            catch
            {
                MessageBox.Show("error3");
            }

            PrintPreview a = new PrintPreview(this, aaa, 2);

            a.ShowDialog();
        }

        private void openPrintP(object sender, DragEventArgs e)
        {
            ArrayList aaa = new ArrayList();

            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    aaa.Add(pic.ImageIndex);
                }

            }
            catch
            {
                MessageBox.Show("error3");
            }

            PrintPreview a = new PrintPreview(this, aaa, 3);

            a.ShowDialog();
        }



        private void openCD(object sender, DragEventArgs e)
        {
            ArrayList aaa = new ArrayList();

            DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect);
            try
            {
                Button btn = (Button)sender;
                btn.BackColor = childButtonColor;
                foreach (ListViewItem pic in listView1.SelectedItems)
                {
                    aaa.Add(pic.ImageIndex);
                }

            }
            catch
            {
                MessageBox.Show("error3");
            }

            Burn a = new Burn(this, aaa);

            a.ShowDialog();
        }














        public void addNewTag(String albumName)
        {
            newThing();

            if (!undoing && !redoing)
            {
                trackNumItems.Add(1);
            }

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                de.Key = "add tag";
                de.Value = albumName;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }
            if (undoing || redoing)
            {
                ButtonTree.ButtonNode newTagName = new ButtonTree.ButtonNode();
                newTagName.NodeButton.Text = albumName;
                tag.AddChild(newTagName);

                //format and add event handlers to the newly created button
                newTagName.NodeButton.Image = resizeImage(new Bitmap(Path.GetDirectoryName(Application.ExecutablePath).Replace("\\bin\\Debug", "\\Icons\\bucket.gif")), 50, 40);
                newTagName.NodeButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                newTagName.NodeButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
                newTagName.NodeButton.BackColor = childButtonColor;
                newTagName.NodeButton.DragDrop += new System.Windows.Forms.DragEventHandler(this.tag_DragDrop);
                newTagName.NodeButton.DragLeave += new System.EventHandler(this.buttonTree1_DragLeave);
                newTagName.NodeButton.DragEnter += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragEnter);
                newTagName.NodeButton.DragOver += new System.Windows.Forms.DragEventHandler(this.buttonTree1_DragOver);

                newTagName.NodeButton.AllowDrop = true;
                newTagName.NodeButton.Name = newTagName.NodeButton.Text;
                newTagName.NodeButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tag_MouseDown);
                dragDropNodeButtons.Add(newTagName.NodeButton);
                newButtons.Add(newTagName.NodeButton);





                redrawTree();
                this.tag.Collapse();
                this.tag.Expand();
            }





            if (undoing || redoing)
            {
                //     allAlbums.Add(albumName, allErasedAlbums[albumName]);
                //     allErasedAlbums.Remove(albumName);






                foreach (DictionaryEntry de in allErasedTags)
                {
                    
                    //mark5
                    allImageTags.Remove(de.Key);
                    allImageTags.Add(de.Key, allErasedTags[de.Key]);
                }


                allErasedTags.Clear();


            }
            else
            {
                //allAlbums.Add(albumName, new ArrayList());
            }

        }







        public void removeTag(String albumName)
        {
            newThing();

            if (!undoing && !redoing)
            {
                trackNumItems.Add(1);
            }

            if (!undoing)
            {


                DictionaryEntry de = new DictionaryEntry();
                de.Key = "remove tag";
                de.Value = albumName;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }
            if (undoing || redoing)
            {
                foreach (ButtonTree.ButtonNode node in tag)
                {
                    if (node.NodeButton.Text.Equals(albumName))
                    {
                        tag.Remove(node);
                        redrawTree();
                        tag.Collapse();
                        tag.Expand();
                        break;
                    }
                }
                allAlbum_Click(null, null);
            }



            //   allErasedAlbums.Add(albumName, allAlbums[albumName]);
            //   allAlbums.Remove(albumName);













        }

        private void lastActionText_TextChanged(object sender, EventArgs e)
        {
            showAnimation();
        }

        private void selectAllBtn_Click(object sender, EventArgs e)
        {
            this.listView1.Focus();
            SendKeys.Send("{HOME}");
            SendKeys.Send("+{END}");
        }







        public void addNewImage(String albumName)
        {
            newThing();

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                de.Key = "add image";
                de.Value = albumName;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }
            if (undoing || redoing)
            {
                System.Console.WriteLine(albumName);

                Image aImage = Bitmap.FromFile(albumName);

                //addImageToAlbum("ALL", browse);

                imageList.Images.Add(aImage);
                imageLocation.Add(albumName);
                FileInfo fileInfo = new FileInfo(albumName);
                String strDir = fileInfo.Name;

                imageCreatedList.Add(fileInfo.CreationTime);
                imageModifiedList.Add(fileInfo.LastWriteTime);
                imageFileNameList.Add(strDir);
                listView1.Items.Add(strDir);
                listView1.TileSize = new System.Drawing.Size(100, 80);
                //
                //make a tag entry for each image    
                allImageTags.Add(browse.ToString(), new ArrayList());
                //
                //make rating default of 0 for each new image
                allImageRatings.Add(browse.ToString(), 0);

                browse++;

                allAlbum_Click(null, null);
            }






        }

        public void removeImage(String albumName)
        {
            newThing();
            int tempp = 0;

            for (int sss = 0; sss < imageLocation.Count; sss++)
            {
                if (imageLocation[sss] == albumName)
                {
                    tempp = sss;
                }
            }

            ListViewItem lvi = listView1.Items[tempp];

            if (!undoing)
            {
                DictionaryEntry de = new DictionaryEntry();
                de.Key = "remove image";
                de.Value = albumName;
                actionHistory.Add(de);

                if (actionHistory.Count == 1)
                {
                    enableButton(undoButton);
                }
            }
            if (undoing || redoing)
            {
                //updateStuff(lvi.ImageIndex);

                imageFileNameList.RemoveAt(lvi.ImageIndex);
                imageCreatedList.RemoveAt(lvi.ImageIndex);
                imageModifiedList.RemoveAt(lvi.ImageIndex);
                imageLocation.RemoveAt(lvi.ImageIndex);
                imageList.Images.RemoveAt(lvi.ImageIndex);
                lvi.Remove();
                allAlbum_Click(null, null);
            }


        }



        Timer clock;

        private void showAnimation()
        {

      
            

            pictureAni.Show();
            pictureStill.Hide();

            clock = new Timer();
            clock.Interval = 3200;
            clock.Tick += new EventHandler(clock_Tick);
            clock.Start();
        }

        void clock_Tick(object sender, EventArgs e)
        {
            clock.Stop();
            pictureAni.Hide();
            pictureStill.Show();
        }

        private void forwardButton_EnabledChanged(object sender, EventArgs e)
        {
            if (forwardButton.Enabled == false)
            {
                label5.Text = "Currently Viewing: ";
            }
            else
            {
                label5.Text = "You were Viewing: ";
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }





    }
}
